import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../interface/root_proxy_model.dart';
import 'user_list_page_model.dart';

class UserListPage extends StatelessWidget {
  final int initIndex;
  final int initCashIndex;

  const UserListPage({super.key, this.initIndex = 1, this.initCashIndex = 0});

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
        providers: [
          ChangeNotifierProxyProvider<RootProxyModel, UserListPageModel>(
            create: (context) => UserListPageModel(initIndex, initCashIndex),
            update: (context, rootProxyModel, leafModel) {
              if (leafModel == null) throw ArgumentError.notNull('leafModel');
              leafModel.roomModel = rootProxyModel;
              return leafModel;
            },
          ),
        ],
        child: Consumer<UserListPageModel>(builder: (context, model, child) {
          return Container(
            constraints: const BoxConstraints(
              minHeight: 579,
            ),
            decoration: const BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(24),
                topRight: Radius.circular(24),
              ),
            ),
            child: Column(
              children: [
                const SizedBox(
                  height: 20,
                ),
                Text('Row('),
                // Row(
                //   mainAxisSize: MainAxisSize.min,
                //   children: [
                //     getTitleWidget(model, T.current!.contribution_list,
                //         model.currentTabIndex == 0, () {
                //       Reporter.track(TrackEvent.roomFunctionClick, {
                //         "rid": model.roomModel.channel!.channelId.toInt(),
                //         "room_type": model.roomModel.channel!.roomTypeObj.type,
                //         "channel_type": model.roomModel.channel!.roomLabel,
                //         "use_type": model.roomModel.channel!.usage,
                //         "is_work": model.roomModel.channel!.inProcessOfSchedule,
                //         "owner_uid": model.roomModel.channel!.owner.id.toInt(),
                //         "role": model.roomModel.channel!.owner.role,
                //         "type": "ranking",
                //         "tool_name": T.current!.contribution_list,
                //       });
                //       model.selectItem(0);
                //     }),
                //     const SizedBox(
                //       width: 27.5,
                //     ),
                //     getTitleWidget(
                //       model,
                //       T.current!.online_audience,
                //       model.currentTabIndex == 1,
                //       () {
                //         Reporter.track(TrackEvent.roomFunctionClick, {
                //           "rid": model.roomModel.channel!.channelId.toInt(),
                //           "room_type":
                //               model.roomModel.channel!.roomTypeObj.type,
                //           "channel_type": model.roomModel.channel!.roomLabel,
                //           "use_type": model.roomModel.channel!.usage,
                //           "is_work":
                //               model.roomModel.channel!.inProcessOfSchedule,
                //           "owner_uid":
                //               model.roomModel.channel!.owner.id.toInt(),
                //           "role": model.roomModel.channel!.owner.role,
                //           "type": "online",
                //           "tool_name": T.current!.online_audience,
                //         });
                //         model.selectItem(1);
                //       },
                //     ),
                //     if ((model.roomModel.channel?.role.value ?? 0) >
                //         RtcUserRole.Guest.value)
                //       const SizedBox(
                //         width: 27.5,
                //       ),
                //     if ((model.roomModel.channel?.role.value ?? 0) >
                //         RtcUserRole.Guest.value)
                //       getTitleWidget(
                //           model, T.current!.admin, model.currentTabIndex == 2,
                //           () {
                //         model.selectItem(2);
                //       }),
                //   ],
                // ),
                Expanded(
                  child: PageView.builder(
                    itemBuilder: (context, position) =>
                        getListItemPage(position, model),
                    itemCount: 3,
                    controller: model.controller,
                    scrollDirection: Axis.horizontal,
                    scrollBehavior: const ScrollBehavior(),
                    onPageChanged: (position) {
                      model.selectItemWithIndex(position);
                    },
                  ),
                ),
              ],
            ),
          );
        }));
  }

  Widget getListItemPage(int position, UserListPageModel model) {
    // if (position == 0) {
    //   //贡献榜
    //   return UserListCashPage(
    //     initCashIndex: model.initCashIndex,
    //   );
    // } else if (position == 1) {
    //   //在线观众
    //   return const UserListOnlinePage();
    // } else if (position == 2) {
    //   return const UserListAdminPage();
    // }
    return Container();
  }

  getTitleWidget(UserListPageModel model, String title, bool isSelected,
      VoidCallback onPressed) {
    return CupertinoButton(
      onPressed: onPressed,
      padding: EdgeInsets.zero,
      minSize: 0,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Text(
            title,
            style: TextStyle(
                fontSize: 15,
                color: isSelected
                    ? const Color(0xff333333)
                    : const Color(0xff999999),
                fontWeight: isSelected ? FontWeight.w500 : FontWeight.w400),
          ),
          const SizedBox(
            height: 1,
          ),
          Container(
              width: 18,
              height: 4,
              decoration: BoxDecoration(
                color:
                    isSelected ? const Color(0xffffd400) : Colors.transparent,
                borderRadius: BorderRadius.circular(2.5),
              )),
        ],
      ),
    );
  }
}
